package com.leetcode.tree.recursion;

import com.leetcode.basic.TreeNode;

/**
 * @author Dennis Li
 * @date 2020/6/15 23:11
 */
public class FindSecondMinimumValue_671 {

    int min, min2 = Integer.MAX_VALUE;

    boolean showed;

    public int findSecondMinimumValue(TreeNode root) {
        min = root.val;
        traverse(root);
        return min2;
    }

    private void traverse(TreeNode root) {
        if (root == null) return;
        if (root.val < min) {
            min2 = min;
            min = root.val;
            showed = true;
        } else if (root.val <= min2 && root.val != min) {
            min2 = root.val;
            showed = true;
        }
        traverse(root.left);
        traverse(root.right);
    }


}
